@extends('admin.master')
<script src="/js/admin/chargeRecords.js"></script>
@section('title', '充值管理')
	
@section('firstItem')
@parent
    <span class="firstItem">充值管理</span>
    <input class="a_indexbg" type="hidden" value="chargerecords" />
@stop
@section('searchList')
@parent
<a class="queryBoxBtn">搜索</a>
<div>
	<input class="chargeQueryInput" type="text" placeholder="输入用户名或设备编号" value="{{ $condition }}" />
</div>
@stop
@section('dataTables')
@parent
<table class="installInfo dataTables" cellspacing="0" cellpadding="0">
	<thead>
		<tr>
			<td>序号</td>
			<td>设备编号</td>
			<td>用户名</td>
			<td style="width: 4%">剩余流量(L)</td>
			<td>剩余天数(D)</td>
			<td>购买模式</td>
			<td style="width: 4%">购买金额(元)</td>
			<td style="width: 4%">购买流量数(L)</td>
			<td>购买天数(D)</td>
			<td>购买人</td>
			<td>后台充值人</td>
			<td style="width: 4%">撤销金额(元)</td>
			<td style="width: 4%">撤销流量数(L)</td>
			<td>撤销天数(D)</td>
			<td>撤销操作人</td>
			<td style="width: 4%">价格(元)</td>
			<td>商户订单号</td>
			<td>备注信息</td>
			<td style="width:7%">时间</td>
			<td>购买记录</td>
			@if($user->hasAnyAccess('superadmin') || $user->hasAnyAccess('finance'))
			<td>充值</td>
			@endif
		</tr>
	</thead>
	<tbody>
		@for($i=0, $chargeRecordCount=count($charge_records); $i<$chargeRecordCount; $i++)
		<tr >
			<td>{{ $i+1 }}</td>
			<td class="DeviceCodeCell devicecodeVal">{{ $charge_records[$i]->device->code }}</td>
			<td class="userNameCell">{{ $charge_records[$i]->device->installInfo->customer_name or '' }}</td>
			<td class="FluxCell">{{ $charge_records[$i]->residual_flow or '/' }}</td>
			<td class="DaysCell">{{ $charge_records[$i]->time_limit or '/'}}</td>
			@if($charge_records[$i]->recharge_mode == 1)
			<td>套餐模式
			@else<td>计量模式
			@endif
			</td>
			<td>{{ $charge_records[$i]->money or 0 }}</td>
			<td>{{ $charge_records[$i]->flow or 0 }}</td>
			<td>{{ $charge_records[$i]->days or 0 }}</td>
			<td>{{ $charge_records[$i]->userInfo->name or '' }}</td>
			<td>{{ $charge_records[$i]->adminInfo->name or '' }}</td>
			<td >{{ is_null($charge_records[$i]->discharge_money)? '': $charge_records[$i]->discharge_money}}</td>
			<td>{{ is_null($charge_records[$i]->discharge_flow)? '': $charge_records[$i]->discharge_flow}}</td>
			<td>{{ is_null($charge_records[$i]->discharge_time)? '': $charge_records[$i]->discharge_time}}</td>
			<td>{{ $charge_records[$i]->dischargeAdmin->name or '' }}</td>
			<td >{{ is_null($charge_records[$i]->price)? '': $charge_records[$i]->price}}</td>
			<td>{{ $charge_records[$i]->order_number or '' }}</td>
			<td class="chargeAddTextCell" style="width:180px;">{{ $charge_records[$i]->remark }}</td>
			<td>{{ $charge_records[$i]->created_at }}</td>
			
			<td><a href="/admin/device/chargeRecords/history?device_id={{ $charge_records[$i]->device_id }}">查看</a></td>
			@if($user->hasAnyAccess('superadmin') || $user->hasAnyAccess('finance'))
			<td class="positionParent">
				<a class="rechargeBtn">充值</a>
				<input class="addresInput" type="hidden" value="" />
				<input class="userListInput" type="hidden" value="" />
				<input class="device_id" type="hidden" value="{{ $charge_records[$i]->device_id }}" />
				<div class="modeBox">
					<a class="meterageMode">计量模式</a>
					<a class="packageMode">套餐模式</a>
				</div>
			</td>
			@endif
		</tr>
		@endfor
	</tbody>
</table>
@stop
@section('page_num')
@if(!is_null($charge_records->first()))
	<?php
	$queryParam = ['device_id' => $charge_records->first()->device_id];
	$queryParam = empty($condition)? $queryParam: array_merge($queryParam, ['condition' => $condition]);  ?>
	{!! $charge_records->appends($queryParam)->render() !!}
@endif

@stop
@section('infor_promit')
@parent
	<!-- 充值编辑框 -->
	<div class="payFlux meterageM" >
		<div class="displayBox p_relative">
			<div>
				<p><span>设备编码:</span><label class="chargeDeviceCode"></label></p>
				<p><span>剩余流量(L):</span><label class="chargeResidueFlux"></label></p>
			</div>
			<div>
				<p><span>用户名:</span><label class="chargeGetUserName"></label></p>
				<p><span>剩余天数(D):</span><label class="chargeResidueDays"></label></p>
			</div>
			<div >
				<p><span>安装地址:</span><label class="chargeGetAddress" style="width: 200px;"></label></p>
			</div>
			<p><textarea class="textareaBox charggeRecord_AddText" placeholder="备注信息："></textarea></p>
			<input type="hidden" class="fluxPrice" value="{{ $price or 0.5 }}" /><!--获取流量单价-->
			<div class="payBox">充值金额(元)：<input class="chargeFluxBox" type="text" placeholder="输入正整数" oninput="myFunction1()"/><label class="required">*</label>
				<div class="moneyNumDrop">
					<a>20</a>
					<a>50</a>
					<a>100</a>
					<a>200</a>
				</div>
			</div>
			<div class="payBox">充值流量(升)：<span class="fluxNumBox" style="margin-left: 20px;"></span></div>
			<label class="labelBox"></label>
		</div>
		<div class="btnBox" >
			<a class="noBtn chargeNoBtn">取消</a>
			<a class="okBtn chargeOkBtn">确定</a>
		</div>
	</div>

	<div class="payFlux packageM" >
		<div class="displayBox p_relative">
			<div>
				<p><span>设备编码:</span><label class="chargeDeviceCode"></label></p>
				<p><span>剩余流量(L):</span><label class="chargeResidueFlux"></label></p>
			</div>
			<div>
				<p><span>用户名:</span><label class="chargeGetUserName" style="width: 200px;"></label></p>
				<p><span>剩余天数(D):</span><label class="chargeResidueDays"></label></p>
			</div>
			<div >
				<p><span>安装地址:</span><label class="chargeGetAddress" style="width: 200px;"></label></p>
			</div>
			<p><textarea class="textareaBox charggeRecord_AddText" placeholder="备注信息："></textarea></p>
			<div class="payBox">充值天数(天)：<input class="chargeFluxBox" type="text" placeholder="输入正整数" oninput="myFunction2()"/><label class="required">*</label>
				<div class="moneyNumDrop">
					<a>20</a>
					<a>50</a>
					<a>100</a>
					<a>200</a>
				</div>
			</div>
			<label class="labelBox"></label>
		</div>
		<div class="btnBox" >
			<a class="noBtn chargeNoBtn">取消</a>
			<a class="okBtn chargeOkBtn">确定</a>
		</div>
	</div>
	<script>
	var reg =/^[0-9]*$/;
		function myFunction1(){
			$(".meterageM .labelBox").html("");
			if(!reg.test($(".meterageM .chargeFluxBox").val())){
				$(".meterageM .labelBox").html("请输入正整数！");
				$(".meterageM .fluxNumBox").html(0);

			}else if($(".meterageM .chargeFluxBox").val()==0){
				$(".meterageM .labelBox").html("请输入正整数！");
				$(".meterageM .fluxNumBox").html(0);
			}else{
				$(".meterageM .labelBox").html("");
				$(".meterageM .fluxNumBox").html(Math.round($(".meterageM .chargeFluxBox").val()/$(".meterageM .fluxPrice").val()));
			}
		}
		function myFunction2(){
			$(".packageM .labelBox").html("");
			if(!reg.test($(".packageM .chargeFluxBox").val())){
				$(".packageM .labelBox").html("请输入正整数！");

			}else if($(".packageM .chargeFluxBox").val()==0){
				$(".packageM .labelBox").html("请输入正整数！");
			}else{
				$(".packageM .labelBox").html("");
			}
		}
	</script>
@stop
